<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Think\Controller;
/**
 * 系统配置控制器
 *
 */
class JisuanpdController extends AdminController{

    public function index(){
        //使用Builder快速建立列表页面。
        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('计算配对');//设置页面标题
        $this->display();
    }
    //计算配对
    public function add()
    {
        $FKUser = M("UserTemppipeiorder");
        $SKUser = M("UserTempskorder");
        $datacig_bfb['name'] = "LBW_SCPIPEI_MONEY"; //获取倍数设置
        $lbw_config_bfb = D('SystemConfig')->where($datacig_bfb)->getField('value');
        //提供帮助匹配信息读取
        $admin['lbw_order_pipei'] = I('post.ppdd');
        $fk_sj = $FKUser->where($admin)->select(); //拿最先匹配的一条数据
        $fk_yuanmoney = $fk_sj[0]["money_total"];//付款数据库直取金额
        $fk_money = $fk_yuanmoney; //* $lbw_config_bfb; //付款金额的参数
        $fk_vipid = $fk_sj[0]["lbw_vipid"];  //付款会员id
        $fk_dh = $fk_sj[0]["lbw_order_pipei"]; //付款匹配订单号
        $fk_fangfa = $fk_sj[0]["peiduifs"];   //付款匹配方法
        $fk_id = $fk_sj[0]["id"];           //匹配付款订单序号
        $fk_zhuangtai = $fk_sj[0]["peidui_status"]; //匹配状态
        $fk_cishu = $fk_sj[0]["peidui_cishu"];
        $fk_name = $fk_sj[0]['fk_name'];  //姓名
        $fk_bankNumber = $fk_sj[0]['bank_number'];
        $fk_bankName = $fk_sj[0]['bank_name'];
        $fk_alipay = $fk_sj[0]['alipay'];
        $fk_sj_mobile = $fk_sj[0]['fk_sj_mobile'];
        $fk_my_mobile = $fk_sj[0]['fk_my_mobile'];
        $fk_yipipei_my=$fk_sj[0]['yipipei_money']; //拿到已匹配金额数据
        $fk_username=$fk_sj[0]['username'];//拿到付款人用户名
        $fk_tuijianName=$fk_sj[0]['tuijianrenxm']; //打款推荐人姓名存入
        $fk_tuijianuserName=$fk_sj[0]['tjr_username']; //打款推荐人姓名存入
        $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '5'); //同会员获得帮助数据剔除
        //获得帮助匹配信息读取
        $admin_two['lbw_order_sk_id'] = I('post.skdd');
        $sk_sj = $SKUser->where($admin_two)->select();
        $sk_money = $sk_sj[0]["money_total"];  //收款金额
        $sk_vipid = $sk_sj[0]["lbw_vipid"];   //收款会员id
        $sk_dh = $sk_sj[0]["lbw_order_sk_id"]; //收款订单号
        $sk_fangfa = $sk_sj[0]["peiduifs"];   //收款支持方法
        $sk_id = $sk_sj[0]["id"]; //匹配收款订单序号
        $sk_zhuangtai = $sk_sj[0]["peidui_status"];  //收款匹配状态
        $sk_cishu = $sk_sj[0]["shoukuan_cishu"];
        $sk_name = $sk_sj[0]['sk_name'];
        $sk_bankNumber = $sk_sj[0]['bank_number'];
        $sk_bankName = $sk_sj[0]['bank_name'];
        $sk_alipay = $sk_sj[0]['alipay'];
        $sk_sj_mobile = $sk_sj[0]['sk_sj_mobile'];
        $sk_my_mobile = $sk_sj[0]['sk_my_mobile'];
        $sk_yipp_money = $sk_sj[0]['yipipei_money'];  //拿到已匹配金额数据
        $sk_username = $sk_sj[0]['username'];  //拿到收款人用户名
        $sk_tuijianName=$sk_sj[0]['tuijianrenxinm'];
        $sk_qianbao=$sk_sj[0]['dt_qb']; //拿到钱包类型
        $sk_tuijianuserName=$sk_sj[0]['tjr_username']; //收款推荐人姓名存入
        //比较两个订单金额大小
        if ($fk_money < $sk_money) {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $fk_money; //付款的金额
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = '0';   //修改付款订单剩余匹配余额(付款小于收款，付款直接全部匹配所以为0)
            $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw); //用付款订单序号
            //收款状态修改
            $data_lbwt['money_total'] = $sk_money - $fk_money;   //更新收款总匹配金额去除匹配掉部分
            $data_lbwt['yipipei_money']=$sk_yipp_money+$fk_money;           //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
            $this->success('计算配对成功', U('Admin/index'));
        } elseif ($fk_money > $sk_money) {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $sk_money; //付款的金额 这里因为收款金额小于付款,所以付款金额要用收款金额数量来存入
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = $fk_money-$sk_money;    //修改付款总金额余额状态
            $data_lbw['yipipei_money']=$fk_yipipei_my+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw);
            //收款状态修改
            $data_lbwt['money_total'] = '0';    //修改收款总金额状态
            $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
            $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
            $this->success('计算配对成功', U('Admin/index'));
        } // elseif($fk_yuanmoney = $sk_money)
        else {
            $SFUser = M("UserPipeioder"); //创建数据对象

            $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
            $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
            $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
            //双方匹配数据入库
            $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
            $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
            $data['dk_creattime'] = $creatTime;      //写入订单创建时间
            $data['dk_money_total'] = $fk_money; //付款的金额
            $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
            $data['dk_dakuan_status'] = '0'; //写入等待打款
            $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
            $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
            $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
            $data['sk_money_total'] = $sk_money; //收款金额
            $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
            $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
            $data['sf_jy_status'] = '0'; //写入双方交易状态
            $data['sk_name'] = $sk_name; //写入收款人姓名
            $data['fk_name'] = $fk_name;//写入付款人姓名
            $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
            $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
            $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
            $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
            $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
            $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
            $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
            $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
            $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
            $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
            $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
            $data['dk_username']=$fk_username; //写入打款人用户名
            $data['sk_username']=$sk_username; //写入收款人用户名
            $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
            $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
            $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
            $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
            $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
            $SFUser->data($data)->add(); //数据入库
            //更改双方临时匹配数据表状态
            //付款状态修改
            $data_lbw['money_total'] = "0";   //修改付款总金额状态
            $data_lbw['peidui_status'] = $fk_zhuangtai + 1;  //修改付款匹配状态
            $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
            $FKUser->where('id=' . $fk_id)->save($data_lbw);
            //收款状态修改
            $data_lbwt['money_total'] = "0";   //修改收款总金额状态
            $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
            $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
            $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
            $SKUser->where('id=' . $sk_id)->save($data_lbwt);
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
            $this->success('计算配对成功', U('Admin/index'));
        }
    }


        public function addtwo(){
            $FKUser = M("UserTemppipeiorder");
            $SKUser = M("UserTempskorder");
            $datacig_bfb['name'] = "LBW_SCPIPEI_MONEY"; //获取倍数设置
            $lbw_config_bfb = D('SystemConfig')->where($datacig_bfb)->getField('value');
            //提供帮助匹配信息读取
            $admin['lbw_order_pipei']=I('post.ppdd');
            $fk_sj = $FKUser->where($admin)->select(); //拿最先匹配的一条数据
            $fk_yuanmoney = $fk_sj[0]["money_total"];//付款数据库直取金额
            $fk_money = $fk_yuanmoney; //付款金额
            $fk_vipid = $fk_sj[0]["lbw_vipid"];  //付款会员id
            $fk_dh = $fk_sj[0]["lbw_order_pipei"]; //付款匹配订单号
            $fk_fangfa = $fk_sj[0]["peiduifs"];   //付款匹配方法
            $fk_id = $fk_sj[0]["id"];           //匹配付款订单序号
            $fk_zhuangtai = $fk_sj[0]["peidui_status"]; //匹配状态
            $fk_cishu = $fk_sj[0]["peidui_cishu"];
            $fk_name = $fk_sj[0]['fk_name'];  //姓名
            $fk_bankNumber = $fk_sj[0]['bank_number'];
            $fk_bankName = $fk_sj[0]['bank_name'];
            $fk_alipay = $fk_sj[0]['alipay'];
            $fk_sj_mobile = $fk_sj[0]['fk_sj_mobile'];
            $fk_my_mobile = $fk_sj[0]['fk_my_mobile'];
            $fk_yipipei_my=$fk_sj[0]['yipipei_money']; //拿到已匹配金额数据
            $fk_username=$fk_sj[0]['username'];//拿到付款人用户名
            $fk_tuijianName=$fk_sj[0]['tuijianrenxm']; //打款推荐人姓名
            $fk_tuijianuserName=$fk_sj[0]['tjr_username']; //打款推荐人姓名存入
            $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '5'); //同会员获得帮助数据剔除
            //获得帮助匹配信息读取
            $admin_two['lbw_order_sk_id']=I('post.skdd');
            $sk_sj = $SKUser->where($admin_two)->select();
            $sk_money = $sk_sj[0]["money_total"];  //收款金额
            $sk_vipid = $sk_sj[0]["lbw_vipid"];   //收款会员id
            $sk_dh = $sk_sj[0]["lbw_order_sk_id"]; //收款订单号
            $sk_fangfa = $sk_sj[0]["peiduifs"];   //收款支持方法
            $sk_id = $sk_sj[0]["id"]; //匹配收款订单序号
            $sk_zhuangtai = $sk_sj[0]["peidui_status"];  //收款匹配状态
            $sk_cishu = $sk_sj[0]["shoukuan_cishu"];
            $sk_name = $sk_sj[0]['sk_name'];
            $sk_bankNumber = $sk_sj[0]['bank_number'];
            $sk_bankName = $sk_sj[0]['bank_name'];
            $sk_alipay = $sk_sj[0]['alipay'];
            $sk_sj_mobile = $sk_sj[0]['sk_sj_mobile'];
            $sk_my_mobile = $sk_sj[0]['sk_my_mobile'];
            $sk_yipp_money =  $sk_sj[0]['yipipei_money']; //已匹配金额数据
            $sk_username = $sk_sj[0]['username'];  //拿到收款人用户名
            $sk_qianbao=$sk_sj[0]['dt_qb']; //拿到钱包类型
            $sk_tuijianName=$sk_sj[0]['tuijianrenxinm']; //收款推荐人姓名存入
            $sk_tuijianuserName=$sk_sj[0]['tjr_username']; //收款推荐人姓名存入
            //双方入库主体
            if ($fk_money < $sk_money) {
                $SFUser = M("UserPipeioder"); //创建数据对象

                $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
                $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
                //双方匹配数据入库
                $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
                $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
                $data['dk_creattime'] = $creatTime;      //写入订单创建时间
                $data['dk_money_total'] = $fk_money; //付款的金额
                $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
                $data['dk_dakuan_status'] = '0'; //写入等待打款
                $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
                $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
                $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
                $data['sk_money_total'] = $sk_money; //收款金额
                $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
                $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
                $data['sf_jy_status'] = '0'; //写入双方交易状态
                $data['sk_name'] = $sk_name; //写入收款人姓名
                $data['fk_name'] = $fk_name;//写入付款人姓名
                $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
                $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
                $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
                $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
                $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
                $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
                $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
                $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
                $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
                $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
                $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
                $data['dk_username']=$fk_username; //写入打款人用户名
                $data['sk_username']=$sk_username; //写入收款人用户名
                $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
                $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
                $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
                $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
                $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
                $SFUser->data($data)->add(); //数据入库
                //更改双方临时匹配数据表状态
                //付款状态修改
                $data_lbw['money_total'] = '0';   //修改付款订单剩余匹配余额(付款小于收款，付款直接全部匹配所以为0)
                $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
                $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
                $FKUser->where('id=' . $fk_id)->save($data_lbw);
                //收款状态修改
                $data_lbwt['money_total'] = $sk_money - $fk_money;   //更新收款总匹配金额去除匹配掉部分
                $data_lbwt['yipipei_money']=$sk_yipp_money+$fk_money;           //更新已匹配金额,用已匹配加上现匹配
                $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
                $SKUser->where('id=' . $sk_id)->save($data_lbwt);
                $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
                $this->success('计算配对成功', U('Admin/index'));
            } elseif ($fk_money > $sk_money) {
                $SFUser = M("UserPipeioder"); //创建数据对象

                $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
                $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
                //双方匹配数据入库
                $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
                $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
                $data['dk_creattime'] = $creatTime;      //写入订单创建时间
                $data['dk_money_total'] = $sk_money; //付款的金额
                $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
                $data['dk_dakuan_status'] = '0'; //写入等待打款
                $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
                $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
                $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
                $data['sk_money_total'] = $sk_money; //收款金额
                $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
                $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
                $data['sf_jy_status'] = '0'; //写入双方交易状态
                $data['sk_name'] = $sk_name; //写入收款人姓名
                $data['fk_name'] = $fk_name;//写入付款人姓名
                $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
                $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
                $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
                $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
                $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
                $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
                $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
                $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
                $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
                $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
                $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
                $data['dk_username']=$fk_username; //写入打款人用户名
                $data['sk_username']=$sk_username; //写入收款人用户名
                $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
                $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
                $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
                $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
                $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
                $SFUser->data($data)->add(); //数据入库
                //更改双方临时匹配数据表状态
                //付款状态修改
                $data_lbw['money_total'] = $fk_money-$sk_money;    //修改付款总金额余额状态
                $data_lbw['yipipei_money']=$fk_yipipei_my+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
                $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
                $FKUser->where('id=' . $fk_id)->save($data_lbw);
                //收款状态修改
                $data_lbwt['money_total'] = '0';    //修改收款总金额状态
                $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
                $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
                $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
                $SKUser->where('id=' . $sk_id)->save($data_lbwt);
                $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
                $this->success('计算配对成功', U('Admin/index'));
            } // elseif($fk_yuanmoney = $sk_money)
            else {
                $SFUser = M("UserPipeioder"); //创建数据对象

                $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                $orderSn = "SF" . $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
                $creatTime = date("Y-m-d H:i:s"); //订单创建时间生成
                //双方匹配数据入库
                $data['dk_lbw_order_pipei'] = $orderSn;   //双方匹配订单号生成
                $data['dk_lbw_vipid'] = $fk_vipid;     //付款会员id入库
                $data['dk_creattime'] = $creatTime;      //写入订单创建时间
                $data['dk_money_total'] = $fk_money; //付款的金额
                $data['dk_odr_ordernumber'] = $fk_dh; //匹配创建的临时单号
                $data['dk_dakuan_status'] = '0'; //写入等待打款
                $data['dk_peiduifs'] = $fk_fangfa; // 可以付款的方式
                $data['sk_lbw_order_pipei'] = $sk_dh; //收款订单号
                $data['sk_lbw_vipid'] = $sk_vipid;  //收款会员id
                $data['sk_money_total'] = $sk_money; //收款金额
                $data['sk_skuan_status'] = '0'; //写入等待对方打款状态
                $data['sk_peiduifs'] = $sk_fangfa;//写入收款支持方法
                $data['sf_jy_status'] = '0'; //写入双方交易状态
                $data['sk_name'] = $sk_name; //写入收款人姓名
                $data['fk_name'] = $fk_name;//写入付款人姓名
                $data['dk_bank_number'] = $fk_bankNumber;  //写入付款人银行账号
                $data['dk_bank_name'] = $fk_bankName;     //写入付款人银行名称
                $data['dk_alipay'] = $fk_alipay;   //写入付款人支付宝
                $data['dk_sj_mobile'] = $fk_sj_mobile; //写入付款人上级手机
                $data['dk_my_mobile'] = $fk_my_mobile; //写入付款人自己手机
                $data['sk_bank_number'] = $sk_bankNumber; //写入收款人银行卡号
                $data['sk_bank_name'] = $sk_bankName;  //写入收款人银行名称
                $data['sk_alipay'] = $sk_alipay;   //写入收款人支付宝
                $data['sk_qianbao_type']=$sk_qianbao; //写入提现钱包类型
                $data['sk_sj_mobile'] = $sk_sj_mobile; //写入收款人上级手机
                $data['sk_my_mobile'] = $sk_my_mobile;  //写入收款人自己手机
                $data['dk_username']=$fk_username; //写入打款人用户名
                $data['sk_username']=$sk_username; //写入收款人用户名
                $data['dk_sj_fristname']=$fk_tuijianName; //写入付款推荐人姓名
                $data['sk_sj_fristname']=$sk_tuijianName; //写入收款推荐人姓名
                $data['fk_tjr_username']=$fk_tuijianuserName; //付款推荐人用户名存入
                $data['sk_tjr_username']=$sk_tuijianuserName; //收款推荐人用户名存入
                $data['sf_dd_crt_time'] = date("Y-m-d H:i:s"); //写入双方匹配订单创建时间
                $SFUser->data($data)->add(); //数据入库
                //更改双方临时匹配数据表状态
                //付款状态修改
                $data_lbw['money_total'] = "0";   //修改付款总金额状态
                $data_lbw['peidui_status'] = $fk_zhuangtai + 1;  //修改付款匹配状态
                $data_lbw['yipipei_money']=$fk_yipipei_my+$fk_money;  //更新已匹配金额,用已匹配加上现匹配
                $data_lbw['peidui_cishu'] = $fk_cishu + 1;  //修改付款次数
                $FKUser->where('id=' . $fk_id)->save($data_lbw);
                //收款状态修改
                $data_lbwt['money_total'] = "0";   //修改收款总金额状态
                $data_lbwt['jiaoyi_zt'] = 1;  //修改匹配状态
                $data_lbwt['yipipei_money']=$sk_yipp_money+$sk_money;  //更新已匹配金额,用已匹配加上现匹配
                $data_lbwt['shoukuan_cishu'] = $sk_cishu + 1;   //修改收款次数
                $SKUser->where('id=' . $sk_id)->save($data_lbwt);
                $SKUser->where('lbw_vipid=' . $fk_vipid)->setField('peidui_status', '0'); //同会员获得帮助数据恢复
                $this->success('计算配对成功', U('Admin/index'));
            }

    }
}